package com.dfbz.demo01_卖票案例;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo12_线程礼让 {
    public static void main(String[] args) {


        Thread t1 = new Thread("线程-A") {
            @Override
            public void run() {
                for (int i = 0; i < 100000; i++) {
                    System.out.println(Thread.currentThread().getName());
                }
            }
        };


        Thread t2 = new Thread("线程-B") {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {

                    System.out.println(Thread.currentThread().getName() + i);
                    if (i == 100) {
                        Thread.yield();
                    }

                    if (i == 200) {
                        Thread.yield();
                    }

                    if (i == 300) {
                        Thread.yield();
                    }

                    if (i == 400) {
                        Thread.yield();
                    }

                }
            }
        };

        t2.setPriority(1);
        t1.setPriority(10);


        t1.start();
        t2.start();

    }
}
